#include "widget.h"
#include "ui_widget.h"
#include <QValidator>
#include <QRegularExpressionValidator>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    ui->pushButton->setEnabled(false);

    //给 lineEdit 注册一个 validator
    ui->lineEdit->setValidator(new QRegularExpressionValidator(QRegularExpression("^\\d{10}$")));
}



Widget::~Widget()
{
    delete ui;
}
void Widget::on_lineEdit_textEdited(const QString &arg1)
{
    qDebug() << arg1;

    QString content = arg1;
    int pos = 0;
    if(ui->lineEdit->validator()->validate(content, pos) == QValidator::Acceptable)
    {
        //验证通过，设置按钮的可用状态为启用
        ui->pushButton->setEnabled(true);
    }
    else
    {
        //验证通过，设置按钮的可用状态为禁用
        ui->pushButton->setEnabled(false);
    }
}

